<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
     
%>
<!DOCTYPE HTML>
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>角色管理</title>
	<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
    
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    
    <link rel="stylesheet" href="./css/x-admin.css" media="all">

    
</head>
<body>
  <div class="x-nav">
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
         <form class="layui-form x-center" action="" style="width:100%">
			<div class="layui-form-pane" style="margin-top: 20px;margin-left: 0px">
				<div class="layui-form-item">
				<!-- <label class="layui-form-label" style="width: 100px">添加日期</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
	             </div>
	             <div class="layui-input-inline">
	                <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
	             </div> -->
				<!-- <div class="layui-input-inline">
	                <select  id="status">
	                    <option value="">请选择状态</option>
	                    <option value="0">启用</option>
	                    <option value="1">禁用</option>
	                </select>
	            </div> -->
				<div class="layui-input-inline">
	               <input type="text" name="name"  id="name"  placeholder="名称" autocomplete="off" class="layui-input">
	            </div>
				<div class="layui-input-inline" style="width:80px">
	               <button type="button" id="queryBtn" onclick="doQuery();" class="layui-btn"><i class="layui-icon">&#xe615;</i></button>
	           	</div>
			</div>
		</div>
		</form>
		<xblock>
       	 	<button class="layui-btn" onclick="x_admin_show('添加角色','jsp/roleManager/addRole.jsp')"><i class="layui-icon"></i>添加</button>
<!--        	 	<button class="layui-btn layui-btn-danger" onclick="exports()"><i class="layui-icon"></i>导出</button> -->
      </xblock>  
      </div>
	  <div class="container" style="width: 100%">
	        <table id="demo-table">
	        </table>
	  </div>
</body>
	<!-- 加载需要的js -->
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/common2.js"></script>
	<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="js/jquery-bootstrap-pagination.js"></script>
    <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
	<script src="js/qunit-1.11.0.js"></script>
	<script src="js/bootstrap-datetimepicker.js"></script>
	<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="bootstrap-table/dist/bootstrap-table.min.js"></script>
	<script src="bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	
	<script src="lib/layui/layui.js" charset="utf-8"></script>
        <script src="js/x-layui.js" charset="utf-8"></script>
        
	<script type="text/javascript" charset="utf-8">

	$(function () {
	    initTable();	
	});

	function doQuery(params){
	    $('#demo-table').bootstrapTable('refresh');    //刷新表格
	}

	function initTable(){
	    var url = "role/roleList";
	    $('#demo-table').bootstrapTable({
	        method:'GET',
	        dataType:'json',
	        contentType: "application/x-www-form-urlencoded",
	        cache: false,
	        striped: true,                              //是否显示行间隔色
	        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	        url:url,
	        height: $(window).height() - 110,
	        width:$(window).width(),
	        showColumns:true,
	        pagination:true,
	        queryParams : queryParams,
	        minimumCountColumns:2, 
	        pageNumber:1,                       //初始化加载第一页，默认第一页
	        pageSize:10,                       //每页的记录行数（*）
	        pageList: [10, 20, 30, 50],        //可供选择的每页的行数（*）
	        uniqueId: "id",                     //每一行的唯一标识，一般为主键列
	        exportDataType: 'all',
	        responseHandler: responseHandler,
	        columns: [
	        //{ field: '', title: '序列', checkbox:true },
	        {
	            field : 'G_ROLE_NAME',
	            title : '角色名称',
	            align : 'center',
	            valign : 'middle'
	           
	        },
            {
	            field : 'G_AUTHORITY',
	            title : '角色权限',
	            align : 'center',
	            valign : 'middle',
				width : '1100px'	           
	        },
	        {
	            field : 'G_CREATE_TIME',
	            title : '添加时间',
	            align : 'center',
	            valign : 'middle',
	               formatter : function (value, row, index){
	                return  timeStamp2String(value);
	            }   
	        },
	        {
	            field : 'upId',
	            title : '操作',
	            align : 'center',
	            valign : 'middle',
	            formatter: operateFormatter //自定义方法，添加操作按钮
	        }
	        ]
	    });
	}
	
	function operateFormatter(value, row, index) {//赋予的参数
		console.log(row);
		return [
			'<button class="layui-btn "  onclick="banner_edit(\''+ row.G_ID + '\')"> <i class="layui-icon">&#xe642;</i>编辑</button>',
			'<button  class="layui-btn layui-btn-danger"    onclick="deleteds(\''+ row.G_ID + '\')"  ><i class="layui-icon">&#xe604;</i> 删除</button>',
			].join('');
} 

	
	function deleteds(id) {
		layer.confirm('确认要删除角色吗？',function(index){
            //发异步删除数据
           $.ajax({
		    type:"get",
			url:"role/deletedRole",
			data:{id:id,},
			success:function(data){
			 	if(data.code==200){
			 		layer.alert("删除成功", {icon: 6},function () {
			 		    location.reload();
			 		});
			    }else{
			    	layer.alert("该角色已被分配,无法删除", {icon: 6},function () {
			 		    location.reload();
			 		});
			 	}
			} 
  		 	});
        });
	}
	
	// 编辑
     function banner_edit (id) {
    	 x_admin_show('编辑角色','jsp/roleManager/updateRole.jsp?id=' + id);
     }
	
     function toTop(id) {
 		layer.confirm('确认要置顶吗？',function(index){
             //发异步删除数据
 			$.ajax({
 			    type:"get",
 				url:"advertising/advertising/toTop",
 				data:{recordId:id,
 					type:1
 					},
 				success:function(data){
 					 //console.log(data)
 				 	if(data.code==200){
 				 		layer.msg('置顶成功!',{icon:3,time:3000});	
 				 		 location.reload();
 				           //window.location.href="jsp/advertisingManager/parentAdvertisingList.jsp";
 				 		}else if(data.code==null){
 				 			layer.msg('权限不足，不能进行操作!',{icon:3,time:3000});			
 				 		}else {
 				 			layer.msg('置顶失败!',{icon:3,time:3000});	
 				 		}
 				 	} 
 	  		 });
         });
 	}
     
     function exports(){
  		var createTimes = $("#LAY_demorange_s").val();
  		var endTime = $("#LAY_demorange_e").val();
  		var name =  $("#name").val();
  		var status = $("#status").find("option:selected").val();
       	       
           window.location.href="systerm/systerm/exportRoleList?createTimes="+createTimes+"&endTime="+endTime+"&name="+name
           +"&status="+status;      
  		
  	}
	
	function operateFormatterImg(value, row, index){			
		return [
				'<img   src='+row.picture+' layer-src='+row.picture+' width="50px"  alt="" height="50px"  data-toggle="modal" data-target="#resetPwd"  />'
			].join('');

	}  
	
	function responseHandler(res) { 
		console.log(res);
	    if (res) {
	        return {
	            "rows" : res.data,
	            "total" : res.totalRecord
	        };
	    } else {
	        return {
	            "rows" : [],
	            "total" : 0
	        };
	    }
	}
	
	function queryParams(params) {
	    var param = {    		
		    	name:$("#name").val(),
	        limit : this.limit, // 页面大小
	        offset : this.offset, // 页码
	    
	        pageNumber : this.pageNumber,
	        pageSize : this.pageSize
	    }
	  

	    return param;
	} 
	
	
	
	
	/* function  setupdate(id ,no,pay_id,retail,second){
     
		   window.location.href="jsp/F3/F3-03/F3-03update.jsp?id="+id+"&no="+no+"&pay_id="+pay_id+"&retail="+retail+"&second="+second   
	} */
	
	
			function  detail(id){		        
				window.location.href="service/serviceDetail?recordId=" + id;
			 }
	//初始化弹出框
	$(function () {
	  	$('[data-toggle="popover"]').popover()
	});
	
	 //时间格式化
   	function timeStamp2String(time){
   	    var datetime = new Date();
   	    datetime.setTime(time);
   	    var year = datetime.getFullYear();
   	    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
   	    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
   	    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
   	    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
   	    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
   	    return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second
   	}
	 
    layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
      laydate = layui.laydate;//日期插件
      lement = layui.element();//面包导航
      laypage = layui.laypage;//分页
      layer = layui.layer;//弹出层
    });
	 
	</script>
</html>


